﻿using System;

namespace Assets.Scripts.Example
{
    public class ExampleHelper
    {
        private const int EXAMPLE1_BTN_COUNT = 5;
        private const int EXAMPLE2_BTN_COUNT = 5;
        private const int EXAMPLE3_BTN_COUNT = 2;
        private const int EXAMPLE4_BTN_COUNT = 3;
        private const int EXAMPLE5_BTN_COUNT = 4;
        private const int EXAMPLE6_BTN_COUNT = 2;
        private const int EXAMPLE7_BTN_COUNT = 2;
        private const int EXAMPLE8_BTN_COUNT = 4;

        public static EnumExample GetExampleTypeByIndex(int index)
        {
            if (index == (int) EnumExample.example1)
            {
                return EnumExample.example1;
            }

            if (index == (int) EnumExample.example2)
            {
                return EnumExample.example2;
            }

            if (index == (int) EnumExample.example3)
            {
                return EnumExample.example3;
            }

            if (index == (int) EnumExample.example4)
            {
                return EnumExample.example4;
            }

            if (index == (int) EnumExample.example5)
            {
                return EnumExample.example5;
            }

            if (index == (int) EnumExample.example6)
            {
                return EnumExample.example6;
            }

            if (index == (int) EnumExample.example7)
            {
                return EnumExample.example7;
            }

            if (index == (int) EnumExample.example8)
            {
                return EnumExample.example8;
            }

            return EnumExample.end;
        }

        public static int GetBtnCount(EnumExample enumExample)
        {
            switch (enumExample)
            {
                case EnumExample.example1:
                    return EXAMPLE1_BTN_COUNT;
                case EnumExample.example2:
                    return EXAMPLE2_BTN_COUNT;
                case EnumExample.example3:
                    return EXAMPLE3_BTN_COUNT;
                case EnumExample.example4:
                    return EXAMPLE4_BTN_COUNT;
                case EnumExample.example5:
                    return EXAMPLE5_BTN_COUNT;
                case EnumExample.example6:
                    return EXAMPLE6_BTN_COUNT;
                case EnumExample.example7:
                    return EXAMPLE7_BTN_COUNT;
                case EnumExample.example8:
                    return EXAMPLE8_BTN_COUNT;
                default:
                    throw new ArgumentOutOfRangeException("enumExample", enumExample, null);
            }

            return 0;
        }

        public static string GetMainBtnLabel(EnumExample exampleType)
        {
            switch (exampleType)
            {
                case EnumExample.example1:
                    return "配置";
                case EnumExample.example2:
                    return "高频函数";
                case EnumExample.example3:
                    return "Log与Conditional";
                case EnumExample.example4:
                    return "数据结构";
                case EnumExample.example5:
                    return "原生API";
                case EnumExample.example6:
                    return "对象池";
                case EnumExample.example7:
                    return "三方库";
                case EnumExample.example8:
                    return "UNSAFE";
                default:
                    throw new ArgumentOutOfRangeException("exampleType", exampleType, null);
            }
        }

        public static string GetSubBtnLabel(EnumExample exampleType, int btnIndex)
        {
            switch (exampleType)
            {
                case EnumExample.example1:
                    return GetExample1BtnLabel(btnIndex);
                case EnumExample.example2:
                    return GetExample2BtnLabe(btnIndex);
                case EnumExample.example3:
                    return GetExample3BtnLabel(btnIndex);
                case EnumExample.example4:
                    return GetExample4BtnLabe(btnIndex);
                case EnumExample.example5:
                    return GetExample5BtnLabe(btnIndex);
                case EnumExample.example6:
                    return GetExample6BtnLabe(btnIndex);
                case EnumExample.example7:
                    return GetExample7BtnLabe(btnIndex);
                case EnumExample.example8:
                    return GetExample8BtnLabe(btnIndex);
                default:
                    throw new ArgumentOutOfRangeException("exampleType", exampleType, null);
            }

            return string.Empty;
        }

        public static string GetExampleDesc(EnumExample exampleType, int btnIndex)
        {
            switch (exampleType)
            {
                case EnumExample.example1:
                    return GetExample1Desc(btnIndex);
                case EnumExample.example2:
                    return GetExample2Desc(btnIndex);
                case EnumExample.example3:
                    return GetExample3Desc(btnIndex);
                case EnumExample.example4:
                    return GetExample4Desc(btnIndex);
                case EnumExample.example5:
                    return GetExample5Desc(btnIndex);
                case EnumExample.example6:
                    return GetExample6Desc(btnIndex);
                case EnumExample.example7:
                    return GetExample7Desc(btnIndex);
                case EnumExample.example8:
                    return GetExample8Desc(btnIndex);
                default:
                    throw new ArgumentOutOfRangeException("exampleType", exampleType, null);
            }

            return string.Empty;
        }


        #region Example1

        private static string GetExample1BtnLabel(int i)
        {
            if (i == 0)
            {
                return "读取XML";
            }

            if (i == 1)
            {
                return "读取Bytes";
            }

            if (i == 2)
            {
                return "使用Capacity";
            }

            if (i == 3)
            {
                return "连续读取";
            }

            if (i == 4)
            {
                return "分帧读取";
            }

            return string.Empty;
        }

        private static string GetExample1Desc(int i)
        {
            if (i == 0)
            {
                return "使用System.Xml系统库读取Xml";
            }

            if (i == 1)
            {
                return "将Xml转为Bytes之后，直接读取Bytes";
            }

            if (i == 2)
            {
                return "在初始化列表时,使用Capacity指定列表大小.";
            }

            if (i == 3)
            {
                return "连续读取" + Consts.EXAMPLE1_MULTI_CONFIG_COUNT + "个Dress.xml";
            }

            if (i == 4)
            {
                return "使用FramingProcessing分帧读取" + Consts.EXAMPLE1_MULTI_CONFIG_COUNT + "个Dress.xml";
            }

            return string.Empty;
        }

        #endregion

        #region Example2

        private static string GetExample2BtnLabe(int i)
        {
            if (i == 0)
            {
                return "MonoBehaviour";
            }

            if (i == 1)
            {
                return "List";
            }

            if (i == 2)
            {
                return "ArrayList";
            }

            if (i == 3)
            {
                return "分别计时";
            }

            if (i == 4)
            {
                return "统一计时";
            }

            return string.Empty;
        }

        private static string GetExample2Desc(int i)
        {
            if (i == 0)
            {
                return "创建" + Consts.EXAMPLE2_PALYER_COUNT + "个物体，MonoBehaviour管理Update";
            }

            if (i == 1)
            {
                return "创建" + Consts.EXAMPLE2_PALYER_COUNT + "个物体，使用List管理每个物体的更新";
            }

            if (i == 2)
            {
                return "创建" + Consts.EXAMPLE2_PALYER_COUNT + "个物体，使用ArrayList管理每个物体的更新";
            }

            if (i == 3)
            {
                return "创建" + Consts.EXAMPLE2_PALYER_COUNT + "个物体，每个物体在Update中倒计时";
            }

            if (i == 4)
            {
                return "创建" + Consts.EXAMPLE2_PALYER_COUNT + "个物体，使用统一的触发器倒计时";
            }

            return string.Empty;
        }

        #endregion

        #region Example3

        private static string GetExample3BtnLabel(int i)
        {
            if (i == 0)
            {
                return "Debug";
            }

            if (i == 1)
            {
                return "LogWrapper";
            }

            return string.Empty;
        }

        private static string GetExample3Desc(int i)
        {
            if (i == 0)
            {
                return "使用UnityEngine.Debug打印" + Consts.EXAMPLE3_LOG_COUNT + "条log";
            }

            if (i == 1)
            {
                return "使用LogWrapper.LogDebug打印" + Consts.EXAMPLE3_LOG_COUNT + "条log";
            }

            return string.Empty;
        }

        #endregion

        #region Example4

        private static string GetExample4BtnLabe(int i)
        {
            if (i == 0)
            {
                return "Class";
            }

            if (i == 1)
            {
                return "struct";
            }

            if (i == 2)
            {
                return "alignment";
            }

            if (i == 3)
            {
                return "遍历";
            }

            if (i == 4)
            {
                return "查找";
            }

            return string.Empty;
        }

        private static string GetExample4Desc(int i)
        {
            if (i == 0)
            {
                return "验证" + Consts.EXAMPLE4_ENTITY_COUNT + "个Class所占内存大小";
            }

            if (i == 1)
            {
                return "验证" + Consts.EXAMPLE2_PALYER_COUNT + "个struct所占内存的大小";
            }

            if (i == 2)
            {
                return "分别打印内存对齐前与对齐后，各变量所占内存地址";
            }

            if (i == 3)
            {
                return "分别遍历包含" + Consts.EXAMPLE4_FIND_COUNT + "个元素的List，Dictioanry，数组。对比性能";
            }

            if (i == 4)
            {
                return "分别查找包含" + Consts.EXAMPLE4_FIND_COUNT + "个元素的List，Dictioanry，数组。对比性能";
            }

            return string.Empty;
        }

        #endregion

        #region Example5

        private static string GetExample5BtnLabe(int i)
        {
            if (i == 0)
            {
                return "Camera.main";
            }

            if (i == 1)
            {
                return "Camera管理器";
            }

            if (i == 2)
            {
                return "RaycastAll";
            }

            if (i == 3)
            {
                return "RaycastNonAlloc";
            }

            return string.Empty;
        }

        private static string GetExample5Desc(int i)
        {
            if (i == 0)
            {
                return "验证" + Consts.EXAMPLE5_CAMERA_TEST_COUNT + "个物体时,调用Camera.main的性能";
            }

            if (i == 1)
            {
                return "验证" + Consts.EXAMPLE5_CAMERA_TEST_COUNT + "个物体时,使用Camera管理器的性能";
            }

            if (i == 2)
            {
                return "验证" + Consts.EXAMPLE5_RAY_TEST_COUNT + "个物体使用RaycastAll发射射线的性能";
            }

            if (i == 3)
            {
                return "验证" + Consts.EXAMPLE5_RAY_TEST_COUNT + "个物体使用RaycastNonAlloc发射射线的性能";
            }

            return string.Empty;
        }

        #endregion

        #region Example6

        private static string GetExample6BtnLabe(int i)
        {
            if (i == 0)
            {
                return "不使用对象池";
            }

            if (i == 1)
            {
                return "使用对象池";
            }

            return string.Empty;
        }

        private static string GetExample6Desc(int i)
        {
            if (i == 0)
            {
                return "验证" + Consts.EXAMPLE6_POOL_TEST_COUNT + "个物体时,不使用对象创建消息实体";
            }

            if (i == 1)
            {
                return "验证" + Consts.EXAMPLE6_POOL_TEST_COUNT + "个物体时,使用对象创建消息实体";
            }

            return string.Empty;
        }

        #endregion

        #region Example7

        private static string GetExample7BtnLabe(int i)
        {
            if (i == 0)
            {
                return "使用CSVReader";
            }

            if (i == 1)
            {
                return "使用文本";
            }

            return string.Empty;
        }

        private static string GetExample7Desc(int i)
        {
            if (i == 0)
            {
                return "验证使用三方库CSVReader读取配置时的性能";
            }

            if (i == 1)
            {
                return "验证使用文本读取配置时的性能";
            }

            return string.Empty;
        }

        #endregion

        #region Example8

        private static string GetExample8BtnLabe(int i)
        {
            if (i == 0)
            {
                return "string.Split";
            }

            if (i == 1)
            {
                return "StringUtil.Split";
            }

            if (i == 2)
            {
                return "string.SubString";
            }

            if (i == 3)
            {
                return "StringUtil.SubString";
            }

            return string.Empty;
        }

        private static string GetExample8Desc(int i)
        {
            if (i == 0)
            {
                return "使用System.string分隔" + Consts.EXAMPLE8_STRING_COUNT + "个字符串性能.";
            }

            if (i == 1)
            {
                return "使用StringUtil分隔" + Consts.EXAMPLE8_STRING_COUNT + "个字符串性能.";
            }

            if (i == 2)
            {
                return "使用System.string截取" + Consts.EXAMPLE8_STRING_COUNT + "个字符串性能.";
            }

            if (i == 3)
            {
                return "使用StringUtil截取" + Consts.EXAMPLE8_STRING_COUNT + "个字符串性能.";
            }

            return string.Empty;
        }

        #endregion
    }
}